#ifndef PM_TASK_HISTORY_H_INCLUDED
#define PM_TASK_HISTORY_H_INCLUDED

#include "pm/task.h"
#include "pm/criteria.h"

namespace pm {

/**
 * \class TaskHistory
 */
class TaskHistory : public Task
{
public:
	db::date update_date;
	
	TaskHistory();
	TaskHistory(wxSQLite3ResultSet& res);
};

/**
 * \class GetTaskHistory
 */
struct GetTaskHistory : public ICriteriaForEach<TaskHistory>
{
	db::ID  id_project;

	GetTaskHistory(const db::ID& idProject);
};


/**
 * \class GetTaskHistoryByProject
 */
struct GetTaskHistoryByProject : public GetTaskHistory
{
	static const char* QUERY;

	GetTaskHistoryByProject(const db::ID& idProject);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * GetTaskHistoryByTask
 */
struct GetTaskHistoryByTask : public GetTaskHistory
{
	db::ID   id_task;

	static const char* QUERY;

	GetTaskHistoryByTask(const db::ID& idProject, const db::ID& idTask);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};


/**
 * \class TaskAndCost
 */
class TaskAndCost : public TaskHistory
{
public:
	db::real  cost_done;
	
	TaskAndCost(wxSQLite3ResultSet& res)
	: TaskHistory(res)
	, cost_done(res, wxT("cost_done"), 0.0)
	{
	}
	
	double total_cost() const { return cost_done() + cost(); }
};

/**
 * \class TaskVsInitial
 */
struct TaskVsInitial
{
	db::ID   id_task;
	db::text name;
	db::real todo;
	db::real done;
	db::real initial;

	TaskVsInitial(wxSQLite3ResultSet& res);
	
	double total() const { return todo() + done(); }
	double difference() const { return initial() - total(); }
};

/**
 * GetTaskHistoryByDate
 */
struct GetTaskHistoryByDate : public ICriteriaForEach<TaskAndCost>
{
	db::ID      id_project;
	db::date    date;

	static const char* QUERY;

	GetTaskHistoryByDate(const db::ID& idProject, const wxDateTime& date);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * GetTasksVsInitial
 */
struct GetTasksVsInitial : public ICriteriaForEach<TaskVsInitial>
{
	db::ID  id_project;
	
	GetTasksVsInitial(const db::ID& idProject);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * \class CreateInitialTaskHistory
 */
struct CreateInitialTaskHistory : public ICriteria
{
	Task m_task;
	
	CreateInitialTaskHistory(const Task& task);
	
	virtual bool query(wxSQLite3Database& db);
};

} // namespace pm

#endif // PM_TASK_HISTORY_H_INCLUDED
